package com.indusfo.spc.client.controller;

import com.indusfo.spc.annotation.UserLoginToken;
import com.indusfo.spc.client.service.ClientPalletService;
import com.indusfo.spc.pojo.Pallet;
import com.indusfo.spc.untlis.JsonXMLUtils;
import com.indusfo.spc.untlis.StringUtils;
import com.indusfo.spc.vo.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author chenm
 * @create 2019-12-06 9:00
 */
@RestController
@RequestMapping("/client/pallet")
public class ClientPalletController {

  @Autowired
  private ClientPalletService clientPalletService;


  @PostMapping("/list")
  @UserLoginToken
  public JSONObject List(@RequestBody Pallet pallet){
    try{
      return clientPalletService.selectList(pallet);
    }catch (Exception e){
      e.printStackTrace();
      return JSONObject.build(JSONObject.ERROR,"系统出错");
    }
  }

  @PostMapping("/untying")
  @UserLoginToken
  public JSONObject Untying(@RequestBody Map<String,Object> models){
    try {
      String palletCode = JsonXMLUtils.obj2json(models.get("palletCode")).replace("\"", "");
      if(StringUtils.isEmpty(palletCode) || palletCode.equals("null")){
        return JSONObject.build(JSONObject.ERROR,"托盘号不可为空");
      }
      return clientPalletService.Untying(palletCode);
    }catch (Exception e){
      e.printStackTrace();
      return JSONObject.build(JSONObject.ERROR,"系统异常，联系管理员");
    }
  }

}
